#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys

out=os.popen("mdb-export -H -d ';' -R '\r\n' -D '%Y-%m-%d' /froggyDatas/samba/partage/Qappli/quadra/database/cpta/DC/003034/qcompta.mdb Ecritures")

file=open("ecrituresQuadra.csv", "w+")
file.truncate()

lines=out.read().split("\r\n")
for line in lines:
	fields=line.split(";")
	if len(fields) > 16:
		if fields[2] == "\"VE\"":
			f=fields[16]
			newF=""
			for i in range(1, len(f)-1):
				if f[i] >= "0" and f[i] <= "9":
					newF+=f[i]
			fields[16]=newF
			l=";".join(fields);
			file.write(l+"\r\n")
file.close()

os.system("mysqlimport -uroot -pc77o4r7e coMexpert_test --local --delete --fields-terminated-by=\";\" --fields-optionally-enclosed-by=\"\\\"\"  --lines-terminated-by=\"\\r\\n\" ecrituresQuadra.csv")
			